package com.example.mine_platform.commom;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
public class Result<T> {
    private static final String SUCCESS = "1";
    private static final String ERROR = "0";
    private String code;
    private String message;
    private T data;

    public Result(T data) {
        this.code = SUCCESS;
        this.message = "success";
        this.data = data;
    }

    public Result() {
            this.code = SUCCESS;
            this.message = "success";
            this.data = null;

    }

    public Result(String code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }
    public static <T> Result<T> success() {
        return new Result<>();
    }
    public static <T> Result<T> error(String message) {
        return new Result<>(ERROR, message);
    }

    public static <T> Result<T> error(String code, String message) {
        return new Result<>(code, message);
    }
}
